from django.contrib import admin

# Register your models here.

import xadmin
from .models import *
from xadmin.views.website import LoginView
from xadmin.views import CommAdminView
from xadmin import views

class LoginViewAdmin(LoginView):
    '''登陆页面显示信息'''
    title = '信息管理系统'
    

class GlobalSetting(CommAdminView):
    '''左上角及浏览器标题'''
    site_title = '信息管理系统'
    '''页脚版权信息'''
    site_footer = 'Copyright © 2018 徐宇坤'
    menu_style = 'accordion'
    model_icon = 'fa fa-lock'

class BaseSetting(object):
    '''表示使用主题功能'''
    enable_themes = True
    use_bootswatch = True

    
class StaffAdmin(object):
    list_display = ('name','sex', 'age', 'shengri', 'address','staff_name', 'subjects')
    search_fields = ('name','sex', 'age', 'shengri', 'address', 'staff_name__department_name', 'subjects__name')
    list_filter = ('name','sex', 'age', 'shengri', 'address','staff_name', 'subjects')
    # 顺序排序
    ordering = ('age', 'name',)
    # 逆序排序，在前面加一个减号"-"，例如按年龄倒序排列
    # ordering = ('-age',)
    style_fields = {'subjects': 'checkbox-inline', }
    
class DepartmentAdmin(object):
    list_dispaly = ('department_name', 'headmaster')


class SubjectsAdmin(object):
    list_display = ('name', 'score',)


class TeachersAdmin(object):
    list_display = ('name',)


xadmin.site.register(LoginView, LoginViewAdmin)
xadmin.site.register(CommAdminView, GlobalSetting)
xadmin.site.register(views.BaseAdminView,BaseSetting)

xadmin.site.register(Staff, StaffAdmin)
xadmin.site.register(Department,DepartmentAdmin)
xadmin.site.register(Subjects, SubjectsAdmin)
xadmin.site.register(Teachers, TeachersAdmin)